package cn.yanjr.common.utils;


import java.util.HashMap;
import java.util.Map;

import cn.yanjr.common.enums.ResultEnums;


/**
 * @author lixiao
 * @date 2019/7/31 14:46
 */
public class Result {
    private boolean success;
    private Map<String, Object> data;
    private Integer code;
    private String msg;

    private Result(boolean success){
        this.success = success;
    }

    private Result(boolean success, Map<String, Object> data){
        this.success = success;
        this.data = data;
    }

    private Result(boolean success, Integer code, String msg){
        this.success = success;
        this.code = code;
        this.msg = msg;
    }
    private Result(boolean success, Map<String, Object> data, Integer code){
    	this.success = success;
    	this.code = code;
        this.data = data;
    }

    public static Result success(Map<String, Object> data){
        return new Result(true, data, ResultEnums.SYSTEM_SUCCESS.getCode());
    }
    public static Result success(Map<String, Object> data,Integer code){
    	return new Result(true, data, code);
    }

    public static Result success(){
        return new Result(true);
    }

    public static Result success(String key, Object value){
        Map<String, Object> data = new HashMap<>(1);
        data.put(key, value);
        return new Result(true, data);
    }

    public static Result error(ResultEnums resultEnums){
        return new Result(false, resultEnums.getCode(), resultEnums.getMsg());
    }

    
    //////////////////////////////////////////////////////////////
    
    
    public boolean isSuccess() {
		return success;
	}

	public void setSuccess(boolean success) {
		this.success = success;
	}

	public Map<String, Object> getData() {
		return data;
	}

	public void setData(Map<String, Object> data) {
		this.data = data;
	}

	public Integer getCode() {
		return code;
	}

	public void setCode(Integer code) {
		this.code = code;
	}

	public String getMsg() {
		return msg;
	}

	public void setMsg(String msg) {
		this.msg = msg;
	}
    
    
    
    
    
    

}
